<?php 

Class indexController extends appController
{
	
	function parseurl($url="")
	{
		$url = rawurlencode(mb_convert_encoding($url, 'gb2312', 'utf-8'));
	
		return $url;
	}
	
	public function set()
	{
		$_SESSION['wxid'] = 20;
	}
	
	public function index()
	{
		/* var_dump($_POST);
		echo "aaa";
		exit;
		
		$appid=Model('Star')->is_appid();
		$secret=Model('Star')->is_ser();
		$weiXinObj= new weixinController();
		
		
		$weiXinObj->getToken($appid,$secret);
		$follower=$weiXinObj->getFollower();
		
		if(!isset($_SESSION['wxid']))
		{
			if(!isset($_GET['code']))
			{
				$url='http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
				$url=$this->parseurl($url);
		
				header('Location:https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$appid.'&redirect_uri='.$url.'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect');
				 
			}
			else
			{
		
				
				 
		
				$arr=$weiXinObj->getUserByCode($appid,$secret,$code);
				$access_token=$arr['access_token'];
				$openid=$arr['openid'];
				 
				if($openid)
				{
		
					$arr=$weiXinObj->getUserInfo($openid,$access_token);
				  
					$nickname = $arr['nickname'];//昵称
					$sex = $arr['sex'];//性别
					$city= $arr['city'];//普通用户个人资料填写的城市
					$country= $arr['country'];//国家，如中国为CN
					$province = $arr['province'];//用户个人资料填写的省份
					$arr['createtime']=$_SERVER['REQUEST_TIME'];
					$wxid=Model('Star')->is_user_existed($openid);
					if(!$wxid)
					{
						$wxid = Model('Star')->insertUser($arr);
					}
					 
					 
					$_SESSION['wx_user']=$arr;
				}
				 
				$_SESSION['wxid'] = $wxid;
				 
		
				header('Location:http://'.$_SERVER['HTTP_HOST'].'/index.php?m=index&g=home&a=index');
		
			}
		}
		else
		{ */
		$var = array("openid","nickname","sex","language","province","city","country","headimgurl","a_type","from");
		
		$data = post_var($var);
		
		if(!$data['openid'])
		{
			echo "非法访问";
			exit;
		}
		
		if($data['a_type'] !="15" || $data['from']!="weisai" || $_SERVER['HTTP_REFERER']!='http://nv.weisai.net/index.php?g=home&m=sign&a=index')
		{
			
			echo "非法访问";
			exit;
		}
		
		
// 		var_dump($_POST);
		
		unset( $data['a_type']);
		unset( $data['from']);
		
		$m = Model('index');
		
		$wxid = $m->get_wxid($data['openid'],$data['headimgurl'],$data['nickname']);
		
		$this->assign('name',$data['nickname']);
		
		
		if($wxid == false &&$data['headimgurl']!=""&&$data['nickname']!="" &&   $_SERVER["REMOTE_ADDR"]!="183.55.203.209" )
		{
// 			$data['nickname'] = $data['niname'];
// 			$data['openid'] = $data['open_id'];
				
// 			unset($data['niname']);
// 			unset($data['open_id']);
			$data['ip'] = $_SERVER['HTTP_REFERER'];
			$data['ips'] = $_SERVER["REMOTE_ADDR"];
// 			echo $_SERVER["REMOTE_ADDR"]."aaa";
// 			exit;
			$wxid = $m->create_wxuser($data);
				
		}
		
		
		
		
		
// 		$_SESSION['wxid'] = $wxid;
		
// 		$info = $m->get_sn_record($wxid);
		
// 		//var_dump($info);
		
// 		$this->assign('name',$info['name']);
// 			$appid=Model('Star')->is_appid();
// 			$secret=Model('Star')->is_ser();
// 			$jssdk = new JSSDK($appid, $secret);
// 			$signPackage = $jssdk->GetSignPackage();
// 			$this->assign('signPackage',$signPackage);
	
		
// 		$this->display('sn.html');
// 		exit;
			
			
			$sn = $m->update_sn_record($wxid);
				
// 			$sn = $m->get_sn_record($_SESSION['wxid']);
			
// 			$tem = "";
// 			for ($i=0;$i<strlen($sn);$i++)
// 			{
// 				if($i%4==0&&$i>0)
// 				{
// 					$tem .="-";
// 				}
// 				$tem .= $sn[$i];
// 			}
			
			$this->assign('sn',$sn);
			
			
			
// 			echo $sn;
			
			$this->display('sn.html');
		}
		
		public function sn()
		{
			$this->assign('sn',"111");
			$this->display('sn.html');
			
		}
	
}